# 文件扫描工具 Makefile

# 编译器和标志
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra -O2 -pthread
INCLUDES = -Iinclude
LIBS = -lsqlite3 -lssl -lcrypto

# 源文件目录
SRCDIR = src
INCDIR = include
BUILDDIR = build

# 源文件和目标文件
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(SOURCES:$(SRCDIR)/%.cpp=$(BUILDDIR)/%.o)
TARGET = filescanner

# 默认目标
all: $(TARGET)

# 创建构建目录
$(BUILDDIR):
	@mkdir -p $(BUILDDIR)

# 编译目标文件
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp | $(BUILDDIR)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

# 链接生成可执行文件
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@ $(LIBS)

# 清理
clean:
	rm -rf $(BUILDDIR) $(TARGET)

# 检查依赖
check-deps:
	@echo "检查依赖..."
	@which g++ > /dev/null || (echo "错误: 需要安装 g++" && exit 1)
	@pkg-config --exists sqlite3 || (echo "错误: 需要安装 libsqlite3-dev" && exit 1)
	@pkg-config --exists openssl || (echo "错误: 需要安装 libssl-dev" && exit 1)
	@echo "依赖检查完成"

# 运行测试
test: $(TARGET)
	@echo "运行基本测试..."
	./$(TARGET) -h

# 调试版本
debug: CXXFLAGS += -g -DDEBUG
debug: $(TARGET)

# 帮助
help:
	@echo "可用目标:"
	@echo "  all          编译程序 (默认)"
	@echo "  clean        清理构建文件"
	@echo "  check-deps   检查依赖"
	@echo "  test         运行基本测试"
	@echo "  debug        编译调试版本"
	@echo "  help         显示此帮助"

.PHONY: all clean check-deps test debug help
